package udf.math;

import java.io.IOException;

import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;


public class Incrementer extends EvalFunc<Tuple> {

	public static Long inc = null;

	public static boolean init = false;

	public synchronized static void Init() {

		inc = new Long(0);
		init =true;
	}

	public synchronized static void increment() {

		inc++;
	}

	public Tuple exec(Tuple input) throws IOException {

		if (!init) {

			Init();
			
		}
		

		Tuple output = TupleFactory.getInstance().newTuple();
		output.append(inc);
		increment();
		return output;

	}

}
